package com.example.myapplication.found.model;

import com.example.myapplication.found.bean.StockBean;
import com.example.myapplication.found.bean.StockKlineBean;
import com.example.myapplication.found.contract.FenxiCallback;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: rongfeng
 * @date: 2022/2/25
 * @description 换手率
 */
public class Fenxi14 extends BaseData {

    FenxiCallback fenxiCallback;

    public Fenxi14(StockBean stockBean, StockBean weekStockBean) {
        super(stockBean, weekStockBean);
    }

    public FenxiCallback getFenxiCallback() {
        return fenxiCallback;
    }

    public void setFenxiCallback(FenxiCallback fenxiCallback) {
        this.fenxiCallback = fenxiCallback;
    }

    @Override
    public void start() {
        test1();
    }

    public static int range0, range1, range2, range3, range4, range5, range6, range7, range8, range9, range10, range11,
            range12, range13, range14, range15, range16, range17, range18, range19, range20, range21;
    public static String startDate;
    public static int maxSize;
    public static int lineTotal;
    public static int stockTotal;
    public static int tuishiTotal;
    static List<String> codeList = new ArrayList<>();


    //涨跌比例
    private void test1() {
        if (!codeList.contains(fundCode)) {
            codeList.add(fundCode);
        } else {
            if (fenxiCallback != null) {
                fenxiCallback.fenxiCallback(1);
            }
            return;
        }
        if (fundName.startsWith("退市")) {
            tuishiTotal++;
        }
        stockTotal++;
        if (stockBean.klineList.size() > maxSize) {
            maxSize = stockBean.klineList.size();
            startDate = stockBean.klineList.get(0).date;
        }
        for (StockKlineBean stockKlineBean : stockBean.klineList) {
            lineTotal++;

            System.out.println(stockKlineBean.date + " " + stockKlineBean.huanshou );


            if (stockKlineBean.huanshou == 0) {
                range0++;
            } else if (stockKlineBean.huanshou > 0 && stockKlineBean.huanshou <= 0.5) {
                range1++;
            } else if (stockKlineBean.huanshou > 0.5 && stockKlineBean.huanshou <= 1) {
                range2++;
            } else if (stockKlineBean.huanshou > 1 && stockKlineBean.huanshou <= 1.5) {
                range3++;
            } else if (stockKlineBean.huanshou > 1.5 && stockKlineBean.huanshou <= 2) {
                range4++;
            } else if (stockKlineBean.huanshou > 2 && stockKlineBean.huanshou <= 2.5) {
                range5++;
            } else if (stockKlineBean.huanshou > 2.5 && stockKlineBean.huanshou <= 3) {
                range6++;
            } else if (stockKlineBean.huanshou > 3 && stockKlineBean.huanshou <= 3.5) {
                range7++;
            } else if (stockKlineBean.huanshou > 3.5 && stockKlineBean.huanshou <= 4) {
                range8++;
            } else if (stockKlineBean.huanshou > 4 && stockKlineBean.huanshou <= 4.5) {
                range9++;
            } else if (stockKlineBean.huanshou > 4.5 && stockKlineBean.huanshou <= 5) {
                range10++;
            } else if (stockKlineBean.huanshou > 5 && stockKlineBean.huanshou <= 5.5) {
                range11++;
            } else if (stockKlineBean.huanshou > 5.5 && stockKlineBean.huanshou <= 6) {
                range12++;
            } else if (stockKlineBean.huanshou > 6 && stockKlineBean.huanshou <= 6.5) {
                range13++;
            } else if (stockKlineBean.huanshou > 6.5 && stockKlineBean.huanshou <= 7) {
                range14++;
            } else if (stockKlineBean.huanshou > 7 && stockKlineBean.huanshou <= 7.5) {
                range15++;
            } else if (stockKlineBean.huanshou > 7.5 && stockKlineBean.huanshou <= 8) {
                range16++;
            } else if (stockKlineBean.huanshou > 8 && stockKlineBean.huanshou <= 8.5) {
                range17++;
            } else if (stockKlineBean.huanshou > 8.5 && stockKlineBean.huanshou <= 9) {
                range18++;
            } else if (stockKlineBean.huanshou > 9 && stockKlineBean.huanshou <= 9.5) {
                range19++;
            } else if (stockKlineBean.huanshou > 9.5 && stockKlineBean.huanshou <= 10) {
                range20++;
            } else if (stockKlineBean.huanshou > 10) {
                range21++;
            }
        }
        if (fenxiCallback != null) {
            fenxiCallback.fenxiCallback(1);
        }
    }


    public static void analysis() {
        System.out.println("A股所有股票涨跌幅度统计");
        System.out.println("退市股票数量：" + Fenxi14.tuishiTotal);
        System.out.println("统计开始日期： " + Fenxi14.startDate + " 截止日期：" + "2022-07-29");
        System.out.println("统计股票数量：" + Fenxi14.stockTotal + " 支");
        System.out.println("总统计次数：" + Fenxi14.lineTotal);
        System.out.println();

        System.out.println(">10%：" + range21 + " " + ((float) range21 / lineTotal) * 100);
        System.out.println("9.5%~10%：" + range20 + " " + ((float) range20 / lineTotal) * 100);
        System.out.println("9%~9.5%：" + range19 + " " + ((float) range19 / lineTotal) * 100);
        System.out.println("8.5%~9%：" + range18 + " " + ((float) range18 / lineTotal) * 100);
        System.out.println("8%~8.5%：" + range17 + " " + ((float) range17 / lineTotal) * 100);
        System.out.println("7.5%~8%：" + range16 + " " + ((float) range16 / lineTotal) * 100);
        System.out.println("7%~7.5%：" + range15 + " " + ((float) range15 / lineTotal) * 100);
        System.out.println("6.5%~7%：" + range14 + " " + ((float) range14 / lineTotal) * 100);
        System.out.println("6%~6.5%：" + range13 + " " + ((float) range13 / lineTotal) * 100);
        System.out.println("5.5~6%：" + range12 + " " + ((float) range12 / lineTotal) * 100);
        System.out.println("5%~5.5%：" + range11 + " " + ((float) range11 / lineTotal) * 100);
        System.out.println("4.5%~5%：" + range10 + " " + ((float) range10 / lineTotal) * 100);
        System.out.println("4%~4.5%：" + range9 + " " + ((float) range9 / lineTotal) * 100);
        System.out.println("3.5%~4%：" + range8 + " " + ((float) range8 / lineTotal) * 100);
        System.out.println("3%~3.5%：" + range7 + " " + ((float) range7 / lineTotal) * 100);
        System.out.println("2.5%~3%：" + range6 + " " + ((float) range6 / lineTotal) * 100);
        System.out.println("2%~2.5%：" + range5 + " " + ((float) range5 / lineTotal) * 100);
        System.out.println("1.5%~2%：" + range4 + " " + ((float) range4 / lineTotal) * 100);
        System.out.println("1%~1.5%：" + range3 + " " + ((float) range3 / lineTotal) * 100);
        System.out.println("0.5%~1%：" + range2 + " " + ((float) range2 / lineTotal) * 100);
        System.out.println("0%~0.5%：" + range1 + " " + ((float) range1 / lineTotal) * 100);
        System.out.println("0%：" + range0 + " " + ((float) range0 / lineTotal) * 100);

    }


    public static double median(List<Float> total) {
        if (total.size() <= 0) {
            return 0;
        }
        double j = 0;
        //集合排序
        Collections.sort(total);
        int size = total.size();
        if (size % 2 == 1) {
            j = total.get((size - 1) / 2);
        } else {
            //加0.0是为了把int转成double类型，否则除以2会算错
            j = (total.get(size / 2 - 1) + total.get(size / 2) + 0.0) / 2;
        }
        return j;
    }

}
